package com.we823.project.model.repo;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.LinkedListMultimap;
import com.we823.project.model.BaseModelWithDate;

@Entity
@Table(name="repo_material_bom")
public class MaterialBomModel extends BaseModelWithDate {

	private static final long serialVersionUID = 4480777829333358842L;

	private String process;
	
	private String code;
	@Transient
	private String name;
	
	private String model;
	
	@Column(name="material_code")
	private String materialCode;
	
	@JSONField(serialzeFeatures=SerializerFeature.DisableCircularReferenceDetect)
	@Transient
	private List<MaterialBomModel> subMaterialBoms;
	
	@JSONField(serialize=false)
	@Transient
	private LinkedListMultimap<String, MaterialBomModel> subMaterialBomMap = LinkedListMultimap.create();
	
	@Column(name="material_name")
	private String materialName;
	@Transient
	private MaterialModel material;
	@Column(name="material_model")
	private String materialModel;
	
	@Column(name="material_desc")
	private String materialDesc;
	
	@Column(name="need_num")
	private Float needNum=0f;
	
	
	@Column(name="spec")
	private String special;
	
	/**
	 * 导体结构
	 */
	private String structure;
	/**
	 * 厚度
	 */
	private String thickness;
	
	/**
	 * 外径
	 */
	@Column(name="outer_diameter")
	private String outerDiameter;
	
	@Column(name="store_type")
	private String storeType;
	
	private String unit;
	
	/**
	 * 计划长度
	 */
	@Column(name="plan_num")
	private Float planNum=null;
	
	@Column(name="box_num")
	private String boxNum;
	
	/**
	 * 对于计算公式来说，有kg/km，根（和计划数长度相同）
	 * 默认是按照每1000米计算每千米的数值
	 */
	@Transient
	private int caculateCode=1000;//计算单位的权值
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getMaterialCode() {
		return materialCode;
	}
	public void setMaterialCode(String materialCode) {
		this.materialCode = materialCode;
	}
	public String getMaterialName() {
		return materialName;
	}
	public void setMaterialName(String materialName) {
		this.materialName = materialName;
	}
	public MaterialModel getMaterial() {
		return material;
	}
	public void setMaterial(MaterialModel material) {
		this.material = material;
	}
	public String getStoreType() {
		return storeType;
	}
	public void setStoreType(String storeType) {
		this.storeType = storeType;
	}
	public String getSpecial() {
		return special;
	}
	public void setSpecial(String special) {
		this.special = special;
	}

	public String getMaterialModel() {
		return materialModel;
	}
	public void setMaterialModel(String materialModel) {
		this.materialModel = materialModel;
	}
	public String getUnit() {
		return unit;
	}
	public void setUnit(String unit) {
		this.unit = unit;
	}
	public Float getNeedNum() {
		return needNum;
	}
	public void setNeedNum(Float needNum) {
		if (needNum==null) {
			needNum=0f;
		}
		this.needNum = needNum;
	}
	public String getBoxNum() {
		return boxNum;
	}
	public void setBoxNum(String boxNum) {
		this.boxNum = boxNum;
	}
	public List<MaterialBomModel> getSubMaterialBoms() {
		return subMaterialBoms;
	}
	public void setSubMaterialBoms(List<MaterialBomModel> subMaterialBoms) {
		this.subMaterialBoms = subMaterialBoms;
	}
	/**
	 * 1000 按照妹1000米去计算
	 * -3 根据根数去计算
	 * 1 根据每米去计算
	 * @return
	 */
	public int getCaculateCode() {
		if(!StringUtils.isEmpty(unit)) {
			switch (unit) {
			case "kg/km":
			case "千克/千米":
				caculateCode=1000;
				break;
			default:
				caculateCode=1;
				break;
			}
		}else {
			caculateCode=1;
		}
		return caculateCode;
	}
	public void setCacluteCode(int cacluteCode) {
		this.caculateCode = cacluteCode;
	}
	public String getProcess() {
		return process;
	}
	public void setProcess(String process) {
		this.process = process;
	}
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	public String getMaterialDesc() {
		return materialDesc;
	}
	public void setMaterialDesc(String materialDesc) {
		this.materialDesc = materialDesc;
	}
	public String getStructure() {
		return structure;
	}
	public void setStructure(String structure) {
		this.structure = structure;
	}
	public String getThickness() {
		return thickness;
	}
	public void setThickness(String thickness) {
		this.thickness = thickness;
	}
	public String getOuterDiameter() {
		return outerDiameter;
	}
	public void setOuterDiameter(String outerDiameter) {
		this.outerDiameter = outerDiameter;
	}
	public Float getPlanNum() {
		return planNum;
	}
	public void setPlanNum(Float planNum) {
		this.planNum = planNum;
	}
	public LinkedListMultimap<String, MaterialBomModel> getSubMaterialBomMap() {
		return subMaterialBomMap;
	}
	public void setSubMaterialBomMap(
			LinkedListMultimap<String, MaterialBomModel> subMaterialBomMap) {
		this.subMaterialBomMap = subMaterialBomMap;
	}
	@Override
	public String toString() {
		return "MaterialBomModel [process=" + process + ", code=" + code
				+ ", name=" + name + ", model=" + model + ", materialCode="
				+ materialCode + ", subMaterialBoms=" + subMaterialBoms
				+ ", subMaterialBomMap=" + subMaterialBomMap
				+ ", materialName=" + materialName + ", material=" + material
				+ ", materialModel=" + materialModel + ", materialDesc="
				+ materialDesc + ", needNum=" + needNum + ", special="
				+ special + ", structure=" + structure + ", thickness="
				+ thickness + ", outerDiameter=" + outerDiameter
				+ ", storeType=" + storeType + ", unit=" + unit + ", planNum="
				+ planNum + ", boxNum=" + boxNum + "]";
	}
	
	
}
